package cn.shengchao.config.mybatis;

import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.continew.starter.extension.datapermission.filter.DataPermissionUserContextProvider;

/**
 * @program: examstarapi
 * @description: 数据权限配置
 * @author: Xiong weiqiang
 * @create: 2025-05-26 16:48
 */
@Configuration
public class DataPermissionAutoConfiguration {



    /**
     * 数据权限拦截器
     */
    @Bean
    public DataPermissionInterceptor dataPermissionInterceptor(DataPermissionHandler dataPermissionHandler) {
        return new DataPermissionInterceptor(dataPermissionHandler);
    }

    /**
     * 数据权限处理器
     */
    @Bean
    public DataPermissionHandler dataPermissionHandler(DataPermissionUserContextProvider dataPermissionUserContextProvider) {
        return new DistributeDataPermissionHandler(dataPermissionUserContextProvider);
    }

    /**
     * 数据权限用户上下文提供者
     */
    @Bean
    public DataPermissionUserContextProvider dataPermissionUserContextProvider() {
        System.out.println("[ContiNew Starter] - Auto Configuration 'DataPermission' completed initialization.");
        return new DataPermissionUserContextProviderImpl();
//        if (log.isErrorEnabled()) {
//            log.error("Consider defining a bean of type '{}' in your configuration.", ResolvableType
//                    .forClass(DataPermissionUserContextProvider.class));
//        }
//        throw new NoSuchBeanDefinitionException(DataPermissionUserContextProvider.class);
    }


}